/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __PQ_HierachyWindow_H__
#define __PQ_HierachyWindow_H__

#include "WidgetBase.h"

namespace PQBuilder
{

	enum HierachyRootType
	{
		HRT_RENDER_SETTING=0,
		HRT_TERRAIN_GROUP,
		HRT_GAME_OBJECT,

		HRT_MAX,
	};

	typedef std::map<int,QTreeWidgetItem*> TreeItemList;
	typedef std::map<QTreeWidgetItem*,int> TreeItemIdList;
	class HierachyTree : 
		public QTreeWidget
	{
		Q_OBJECT
	public:
		HierachyTree(QWidget *parent = 0);
		~HierachyTree();
		void addItem(int id,QTreeWidgetItem* item);

		void addTerrainGroup(PQEngine::TerrainGroupObject* object);//special
		void addTerrainObject(PQEngine::TerrainObject* object);

		void addChildGameObject(PQEngine::GameObject *parent,PQEngine::GameObject *child);
		void addGameObject(PQEngine::GameObject *obj);
		void removeChildGameObject(PQEngine::GameObject *parent,PQEngine::GameObject *child);
		void selectGameObject(PQEngine::GameObject *object);
	protected:
		void mousePressEvent(QMouseEvent *evt);

	public slots:
		void OnItemClicked(QTreeWidgetItem* item, int column);
		void OnItemDoubleClicked(QTreeWidgetItem* item, int column);
		void OnCreateTerrainSlot();
	private:
		QTreeWidgetItem *_rootItems[HRT_MAX];
		QMenu *_createTerrainMenu;

		TreeItemList _objectItems;
		TreeItemIdList _objectIds;
	};

	
	class HierachyWindow : 
		public WidgetBase
	{
	public:
		HierachyWindow(QWidget *parent = 0);
		~HierachyWindow();
	public:
		void OnGameObjectCreated(PQEngine::GameObject* object);
		void OnGameObjectDeleted(PQEngine::GameObject* object);
		void OnGameObjectSelected(PQEngine::GameObject* object);
		void OnGameObjectDeselected(PQEngine::GameObject* object);

		//Listen scene event then update ui widget,obselete
		void OnAddChildGameObject(PQEngine::GameObject *parent,PQEngine::GameObject *child);
		void OnRemoveChildGameObject(PQEngine::GameObject *parent,PQEngine::GameObject *child);
	private:
		HierachyTree *_treeWidget;
		
	};
}

#endif
